package com.changgou.seckill.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author tang.qingbo
 * @Date 2020/9/9 13:57
 * @Version 1.0
 */
@Configuration
public class SeckillOrderConfig {
    /**
     * 创建队列
     */
    @Bean("seckillOrderQueue")
    public Queue seckillOrderQueue() {
        return QueueBuilder.durable("seckillOrderQueue").build();
    }

    /**
     * 创建交换机
     */
    @Bean("seckillOrderExchange")
    public Exchange seckillOrderExchange() {
        return ExchangeBuilder.directExchange("seckillOrderExchange").build();
    }

    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding queueBindingExchange(@Qualifier("seckillOrderQueue") Queue queue,@Qualifier("seckillOrderExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("seckillOrderQueue").noargs();
    }
}
